package com.zjsru.leetcode75.level1.tree;

/**
 * @Author: cookLee
 * @Date: 2023-12-13
 * 二叉树的最大深度
 */
public class MaxDepth {

    /**
     * 主
     * \
     * 输入：root = [3,9,20,null,null,15,7]
     * 输出：3
     * @param args args
     */
    public static void main(String[] args) {
        TreeNode tree = new TreeNode(3, new TreeNode(9 ,null, null), new TreeNode(20, new TreeNode(15,null,null), new TreeNode(7, null, null)));
        MaxDepth maxDepth = new MaxDepth();
        System.out.println(maxDepth.maxDepth(tree));
    }


    /**
     * 最大深度
     * bfs
     * @param root 根
     * @return int
     */
    public int maxDepth(TreeNode root) {
        if(root == null){
            return 0;
        }else{
            int leftH = this.maxDepth(root.left);
            int rightH = this.maxDepth(root.right);
            return Math.max(leftH,rightH) + 1;
        }
    }


}
